function HandleDialogWeeklyWage(gui, items, options) {
  this._gui = gui;
  this._items = items;
  this._options = options;

  this._operator = (options && options.user) ? options.user : null;
  this._now = (options && options.now) ? options.now : null;
  this._wage = (options && options.wage) ? options.wage : null;
  
  this._createElements();
};

HandleDialogWeeklyWage.prototype._createElements = function() {
  var _self = this;
  this._hourlyRate = 0;
  tr = this._gui.mains.insertRow(-1);
  td = tr.insertCell(-1);
  td.style.backgroundColor = '#fff';
  td.colSpan = 8;
  td.appendChild(DOMUtils.getLoadingImage());
  
  this._loadData();
};

HandleDialogWeeklyWage.prototype._loadData = function() {
  this._users = null;
  this._retrieveUsers();
};

HandleDialogWeeklyWage.prototype._verifyData = function() {
  if (this._users) {
    this._updateElements();
  }
};

HandleDialogWeeklyWage.prototype._retrieveUsers = function() {
  var _self = this;
  /*new RequestUtils()._read('user', null, null, null, null, 'd.type', null, function(result, params) { _self._users = result.data;
                                                                                                      _self._verifyData.call(_self);
                                                                                                    }, null);
*/
  new RequestUtils()._mysql('v1user', null, function(result, params) { _self._designers = result.data;
                                                                          _self._verifyData.call(_self);
                                                                        }, {php:'customphp/mysqlread.php'});   
};

HandleDialogWeeklyWage.prototype._updateElements = function() {
  var tr, td, _self = this;

  for(var i = 0, il = this._users.length; i < il; i++) {
    var u = this._users[i];
    if (u.skill.employmentType == 1) {
      var exp = Expense.instance();
      exp.userTrackId = this._operator.trackId;
      exp.userAccount = this._operator.account;
      exp.createdDate = this._now;
      exp.payDate = this._wage.date;
      exp.payee = u.account;
      exp.particular = 'Wage (Fulltime)';
      exp.amount = (parseFloat(u.skill.yearlyRate, 10) / 52).toFixed(2);
      exp.isWeeklyPay = 1;
      this._items[this._items.length] = exp;
    }
    if (u.skill.employmentType == 2) {
      exp1= Expense.instance();
      exp1.userTrackId = this._operator.trackId;
      exp1.userAccount = this._operator.account;
      exp1.createdDate = this._now;
      exp1.payDate =  this._wage.date;
      exp1.payee = u.account;
      exp1.particular = 'Wage (Parttime)';
      exp1.amount = parseFloat(u.skill.hourlyRate, 10).toFixed(2);
      this._hourlyRate = u.skill.hourlyRate;
      exp1.isWeeklyPay = 1;
      this._items[this._items.length] = exp1;
    }
  }
  this._wageModify();
};

HandleDialogWeeklyWage.prototype._wageModify = function() {
  var _self = this, unique = MiscUtils.unique();
  DOMUtils.removeTableRows(this._gui.mains, 1);
  
  if (this._items.length == 0) {
    tr = this._gui.mains.insertRow(-1);
    tr.className = 'roweven';
    td = tr.insertCell(-1);
    td.colSpan = 8;
    td.style.height = '24px';
    td.style.textAlign = 'center';
    td.appendChild(document.createTextNode('N/A'));
  }
  for (var i = 0, il = this._items.length; i < il; i++) {
    var wage = this._items[i];
    tr = this._gui.mains.insertRow(-1);
    tr.className = (tr.rowIndex % 2 == 0) ? 'roweven' : 'rowodd';
    
    td = tr.insertCell(-1);
    td.style.height = '25px';
    td.style.width = '80px';
    td.style.textAlign = 'center';
    td.style.borderRight = 'solid 1px #885b5d';
    td.style.borderBottom = 'solid 1px #885b5d';
    td.style.borderLeft = 'solid 1px #885b5d';
    td.appendChild(document.createTextNode(SimpleDate.format(wage.createdDate)));
    
    td = tr.insertCell(-1);
    td.style.width = '80px';
    td.style.textAlign = 'center';
    td.style.borderRight = 'solid 1px #885b5d';
    td.style.borderBottom = 'solid 1px #885b5d';
    td.appendChild(document.createTextNode(SimpleDate.format(wage.payDate)));
    
    td = tr.insertCell(-1);
    td.style.textAlign = 'left';
    td.style.width = '132px';
    td.style.padding = '0 0 0 12px';
    td.style.borderRight = 'solid 1px #885b5d';
    td.style.borderBottom = 'solid 1px #885b5d';
    td.appendChild(document.createTextNode(wage.payee));
    
    td = tr.insertCell(-1);
    td.style.textAlign = 'left';
    td.style.width = '130px';
    td.style.padding = '0 0 0 12px';
    td.style.borderRight = 'solid 1px #885b5d';
    td.style.borderBottom = 'solid 1px #885b5d';
    td.appendChild(document.createTextNode(wage.particular));
    
    td = tr.insertCell(-1);
    td.style.textAlign = 'center';
    td.style.width = '75px';
    td.style.borderRight = 'solid 1px #885b5d';
    td.style.borderBottom = 'solid 1px #885b5d';
    var input = DOMUtils.createInput('', unique + '_' + i + '_amoumt', 'text', wage.amount, null);
    input.style.width = '65px';
    input.style.height = '16px';
    input.style.borderLeft='solid 1px #d2c4b9';
    input.style.borderTop= 'solid 1px #d2c4b9';
    input.style.borderRight= 'solid 1px #fff';
    input.style.borderBottom= 'solid 1px #fff';
    input._wage = wage;
    input.onchange = function() { this._wage.amount = this.value; };
    td.appendChild(input);
    
    td = tr.insertCell(-1);
    td.style.textAlign = 'center';
    td.style.width = '75px';
    td.style.borderRight = 'solid 1px #885b5d';
    td.style.borderBottom = 'solid 1px #885b5d';
    var input = DOMUtils.createInput('', '', 'text', '1', null);
    if (wage.particular == 'Wage (Fulltime)') {
      input.disabled = true;
      input.value = '';
    }
    input.style.width = '65px';
    input.style.height = '16px';
    input.style.borderLeft='solid 1px #d2c4b9';
    input.style.borderTop= 'solid 1px #d2c4b9';
    input.style.borderRight= 'solid 1px #fff';
    input.style.borderBottom= 'solid 1px #fff';
    input._wage = wage;
    input._index = i;
    input.onchange = function() { this._wage.amount = (this.value * _self._hourlyRate).toFixed(2);
                                  document.getElementById(unique + '_' + this._index + '_amoumt').value = this._wage.amount;
                                };
    td.appendChild(input);
    
    td = tr.insertCell(-1);
    td.style.textAlign = 'center';
    td.style.width = '180px';
    td.style.borderRight = 'solid 1px #885b5d';
    td.style.borderBottom = 'solid 1px #885b5d';
    var input = DOMUtils.createInput('', '', 'text', wage.note, null);
    input.style.width = '212px';
    input._wage = wage;
    input.onchange = function() { this._wage.note = this.value; };
    td.appendChild(input);
    
    td = tr.insertCell(-1);
    td.style.textAlign = 'center';
    td.style.borderRight = 'solid 1px #885b5d';
    td.style.borderBottom = 'solid 1px #885b5d';
    var remove = DOMUtils.createInput('', '', 'button', 'Remove', null);
    remove._wage = wage;
    remove.onclick = function() { MiscUtils.remove(_self._items, this._wage, ['trackId']);
                                  _self._wageModify();
                                };
    td.appendChild(remove);
  }
};
